
<?php
	

defined('_JEXEC') or die();
jimport('joomla.application.component.model');

class NBEventMapsModelNBEventMap extends JModel
{
	function __construct() 
    { 
        parent::__construct(); 
		$mainframe = &JFactory::getApplication(); 
        
        $this->_layout = JRequest::getVar('layout', '', '', 'str'); 
        $this->_id = JRequest::getVar('id', 0, '', 'int'); 

        $this->_total   = null; 
        $this->_result  = null; 
        $this->_result2 = null; 
        $this->_result_personnalisation = null; 
		$this->_num_marqueurs = 0;

        $config =& JComponentHelper::getParams('com_nbeventmap'); 

        $lang = JFactory::getLanguage(); 
        $tag_lang=(substr($lang->getTag(),0,2)); 
		 
		JHTML::_( 'behavior .mootools' );

		$doc =& JFactory::getDocument();
		$actif = $doc->getMetaData('nbeventmap');

		if (!defined( '_JOS_NBEVENTMAP_CSS' ))
		{
			
			define( '_JOS_NBEVENTMAP_CSS', 1 );
	
			$doc->addCustomTag( '<link rel="stylesheet" href="'.JURI::base().'components/com_nbeventmap/views/nbeventmap/nbeventmap.css" type="text/css" />'); 
			$doc->addCustomTag( '<link rel="stylesheet" href="'.JURI::base().'components/com_nbeventmap/views/nbeventmap/nbeventmap2.css" type="text/css" />'); 
		}
		
		if (!defined( '_JOS_NBEVENTMAP_LIGHTBOX' ))
		{
			
			define( '_JOS_NBEVENTMAP_LIGHTBOX', 1 );	
			
			$doc->addCustomTag( '<link rel="stylesheet" type="text/css" href="'.JURI::base().'components/com_nbeventmap/floatbox/floatbox.css" />');
			$doc->addCustomTag( '<script type="text/javascript" src="'.JURI::base().'components/com_nbeventmap/floatbox/floatbox.js"></script>');
		}
		
		if (!defined( '_JOS_NBEVENTMAP_APIV2' ))
		{
			
			define( '_JOS_NBEVENTMAP_APIV2', 1 );

			$doc->addCustomTag( '<script type="text/javascript" 
				src="http://maps.google.com/maps?file=api&amp;v=2&amp;hl='.$tag_lang.'&amp;sensor=false&amp;key='.$this->_getGoogleAPIKey().'"> 
			</script>'); 
			$doc->addCustomTag( '<script type="text/javascript"> 
				function setDirections(num) { 
					if (document.getElementById("select_from"+num).value != "") { 
						fromAddress = document.getElementById("select_from"+num).value; 
					} else { 
						fromAddress = document.getElementById("text_from"+num).value; 
					}; 
					if (document.getElementById("select_to"+num).value != "") { 
						toAddress = document.getElementById("select_to"+num).value; 
					} else { 
						toAddress = document.getElementById("text_to"+num).value; 
					}; 
					var gdirName = "gdir"+num; 
					eval(gdirName).load("from: " + fromAddress + " to: " + toAddress); 
				}; 
			</script>'); 
		};
    }

	function _getQuery()
    {
        $db     = JFactory::getDBO();
        
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
        $params	   = clone($mainframe->getParams('com_nbeventmap'));
        $tri       = $params->get('orderby_pri');

 		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

       switch ($tri) {
        case 'alpha' :
            $order = "\n ORDER BY a.nom";
            break;
        case 'ralpha' :
            $order = "\n ORDER BY a.nom DESC";
            break;
        case 'ville' :
            $order = "\n ORDER BY a.ville, a.nom";
            break;
        case 'rville' :
            $order = "\n ORDER BY a.ville DESC, a.nom DESC";
            break;
        case 'pays' :
            $order = "\n ORDER BY a.pay, a.ville, a.nom";
            break;
        case 'rpays' :
            $order = "\n ORDER BY a.pay DESC, a.ville DESC, a.nom DESC";
            break;
        default :
            
            $order = "\n ORDER BY a.start_date ASC";
            break;
        }

        $select = 'SUBSTRING(a.start_date,1,4) AS start_dates,a.*, b.title, b.description as cat_description, c.catid as article_id, '.
				' (SELECT d.alias FROM #__categories AS d WHERE d.id=c.catid) as article_alias , '.
				' (SELECT d.id FROM #__categories AS d WHERE d.id=c.catid) as article_id , '.
				' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '.
				' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, '.
				' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as article_slug ';
        $from   = '#__nbeventmap AS a';
		$joins[] = 'INNER JOIN #__categories AS b on a.catid = b.id';
		$joins[] = 'LEFT OUTER JOIN #__content AS c on a.article_id = c.id';

        $wheres[] = 'a.published = 1';
		
		$user =& JFactory::getUser();
		$aid = $user->get('aid', 0);
		
        if (!empty($this->_id)) {
            if ($this->_layout == 'categorie') {
				$_catids = $this->verif_catid($this->_id);
				foreach ($_catids as $_catid)
				{
					$wheresOr[] = 'a.catid = '.$_catid.'';
				}
				$wheres[] = '('.implode( "\n OR ", $wheresOr).')';
			} else {
            	$wheres[] = 'a.id = '.$this->_id.'';
			}
        };
		
		if ($params->get('nbeventmap_filtre')==1) {

			
			$file = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php';
			if(!file_exists($file)) {
			
				$search_nbeventmap = $mainframe->getUserStateFromRequest( $option.$Itemid.'search_nbeventmap', 'search_nbeventmap', '',    'string' );
				$search_nbeventmap = JString::strtolower($search_nbeventmap);
				if ($search_nbeventmap) {
					$wheres[] = '(LOWER( nom ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( intro ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( message ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( adresse ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( adresse2 ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( ville ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( departement ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( pay ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( email ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( web ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					') ';
				}
			};
	
			$filtreville = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtreville', 'filtreville', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --', 'string' );
			$filtredepartement = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtredepartement', 'filtredepartement', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --', 'string' );
			$filtrepays = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrepays', 'filtrepays', '-- '.JText::_( 'NBEVENTMAP_PAYS_FILTRE' ).' --', 'string' );
			$filtrecategorie = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrecategorie', 'filtrecategorie', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --', 'string' );

			if ($filtreville{0}<>'-') {
				$wheres[] = 'ville = \''.addslashes($this->_getVilleByID($filtreville)).'\'';
			}
			if ($filtredepartement{0}<>'-') {
				$wheres[] = 'departement = \''.addslashes($this->_getDepartementByID($filtredepartement)).'\'';
			}
			if ($filtrepays{0}<>'-') {
				$wheres[] = 'pay = \''.addslashes($this->_getPaysByID($filtrepays)).'\'';
			}	
			if ($filtrecategorie{0}<>'-') {
				$wheres[] = 'b.id = \''.$filtrecategorie.'\'';
			}
		};

        $query = "SELECT " . $select .
                "\n FROM " . $from .
				"\n " . implode ( ' ', $joins ) .
                "\n WHERE " . implode( "\n  AND ", $wheres ).
                $order;
				
        return $query;
    }

	function _getQuery_orderA()
    {
        $db     = JFactory::getDBO();
        
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
        $params = clone($mainframe->getParams('com_nbeventmap'));

        $order = "\n ORDER BY a.nom";

        $select = 'a.*, b.title, b.description as cat_description';
        $from   = '#__nbeventmap AS a, #__categories AS b';

		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

        $wheres[] = 'a.published = 1';
        $wheres[] = 'a.catid = b.id';
		
        if (!empty($this->_id)) {
            if ($this->_layout == 'categorie') {
				$_catids = $this->verif_catid($this->_id);
				foreach ($_catids as $_catid)
				{
					$wheresOr[] = 'a.catid = '.$_catid.'';
				}
				$wheres[] = '('.implode( "\n OR ", $wheresOr).')';
			} else {
            	$wheres[] = 'a.id = '.$this->_id.'';
			}
        };

		if ($params->get('nbeventmap_filtre')==1) {

			
			$file = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php';
			if(!file_exists($file)) {
			
				$search_nbeventmap = $mainframe->getUserStateFromRequest( $option.$Itemid.'search_nbeventmap', 'search_nbeventmap', '',    'string' );
				$search_nbeventmap = JString::strtolower($search_nbeventmap);
				if ($search_nbeventmap) {
					$wheres[] = 'LOWER( nom ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( intro ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( message ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( adresse ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( adresse2 ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( ville ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( departement ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( pay ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( email ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false ).
					' OR LOWER( web ) LIKE '.$db->Quote( '%'.$db->getEscaped( $search_nbeventmap, true ).'%', false );
				}
			};
	
	
			$filtreville = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtreville', 'filtreville', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --', 'string' );
			$filtredepartement = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtredepartement', 'filtredepartement', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --', 'string' );
			$filtrepays = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrepays', 'filtrepays', '-- '.JText::_( 'NBEVENTMAP_PAYS_FILTRE' ).' --', 'string' );
			$filtrecategorie = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrecategorie', 'filtrecategorie', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --', 'string' );
	
			if ($filtreville{0}<>'-') {
				$wheres[] = 'ville = \''.addslashes($this->_getVilleByID($filtreville)).'\'';
			}
			if ($filtredepartement{0}<>'-') {
				$wheres[] = 'departement = \''.addslashes($this->_getDepartementByID($filtredepartement)).'\'';
			}
			if ($filtrepays{0}<>'-') {
				$wheres[] = 'pay = \''.addslashes($this->_getPaysByID($filtrepays)).'\'';
			}	
			if ($filtrecategorie{0}<>'-') {
				$wheres[] = 'b.id = \''.$filtrecategorie.'\'';
			}
		};

        $query = "SELECT " . $select .
                "\n FROM " . $from .
                "\n WHERE " . implode( "\n  AND ", $wheres ).
                $order;
        return $query;
    }

	function verif_catid($id)
	{
		
		
		
		$ids[] = $id;
		$count_ids = count($ids);
		
		for ($i = 0; $i < $count_ids; $i++) {
			$ids = array_merge(array_slice($ids, 0, $i+1), $this->_enfant($ids[$i]), array_slice($ids, $i+1));
			$count_ids = count($ids);
		}

		return $ids;
	}

	function _enfant($id)
	{
		$db	= JFactory::getDBO();
		$query = "SELECT id" .
				"\n FROM #__categories" .
				"\n WHERE parent_id = ".$id .
				"\n AND published = true" .
				"\n ORDER BY title";
    	$db->setQuery( $query );
		$result = $db->loadResultArray();
		return $result;
	}
	
	function getPersonnalisation()
	{
		$mainframe = &JFactory::getApplication(); 
		$db	= JFactory::getDBO();
        $params = clone($mainframe->getParams('com_nbeventmap'));
		$perso  = $params->get('id_perso');

		$query = "SELECT *" .
				"\n FROM #__nbeventmap_personnalisation" .
				"\n WHERE id = ".$perso;

		if (empty($this->_result_personnalisation))
		{
			$db->setQuery( $query );
			$this->_result_personnalisation = $db->loadObject();
		}
		return @$this->_result_personnalisation;
	}
	
	function getTotal()
	{
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 

		
		if (empty($this->_total))
		{
			$query = $this->_getQuery();

			
			$file = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php';
			if(file_exists($file)) {
			
				$this->_total = $this->_getList( $query );
				$search_nbeventmap = $mainframe->getUserStateFromRequest( $option.$Itemid.'search_nbeventmap', 'search_nbeventmap', '',    'string' );
				$search_nbeventmap = JString::strtolower($search_nbeventmap);
				if ($search_nbeventmap) {
					$Resultat_filtre = 0;
					foreach ($this->_total as $result) {
						if ((!(strpos(JString::strtolower($result->nom),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->intro),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->message),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse2),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->ville),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->departement),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->pay),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->email),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->web),$search_nbeventmap)===false))) {
							$Resultat_filtre ++;
						}
					};
					$this->_total=$Resultat_filtre;
				}else{
					$this->_total = $this->_getListCount($query);
				};
			}else{
				$this->_total = $this->_getListCount($query);
			};
		}
		return $this->_total;
	}
	
	function _getQueryPlugin( $options )
	{
		$db			= JFactory::getDBO();

		foreach ($options as $option)
		{
			$wheresOr[]= 'a.id = \''.$option.'\'';
		}
		$wheres[]="(".implode( "\n OR ", $wheresOr ).")";

		$select = 'a.*, b.title, c.catid as article_id,'.
				' (SELECT d.alias FROM #__categories AS d WHERE d.id=c.catid) as article_alias , '.
				' (SELECT d.id FROM #__categories AS d WHERE d.id=c.catid) as article_id , '.
				' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '.
				' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, '.
				' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as article_slug ';
        $from   = '#__nbeventmap AS a';
		$joins[] = 'INNER JOIN #__categories AS b on a.catid = b.id';
		$joins[] = 'LEFT OUTER JOIN #__content AS c on a.article_id = c.id';

		$wheres[] = 'a.published = 1';

		$user =& JFactory::getUser();
		$aid = $user->get('aid', 0);
		

		$query = "SELECT " . $select .
				"\n FROM " . $from .
				"\n " . implode ( ' ', $joins ) .
				"\n WHERE " . implode( "\n  AND ", $wheres );

		return $query;
	}
	
	function _getQueryPluginCatid( $options )
	{
		$db			= JFactory::getDBO();

		foreach ($options as $option)
		{
			$wheresOr[]= 'a.catid = \''.$option.'\'';
		}
		$wheres[]="(".implode( "\n OR ", $wheresOr ).")";

		$select = 'a.*, b.title, c.catid as article_id,'.
				' (SELECT d.alias FROM #__categories AS d WHERE d.id=c.catid) as article_alias , '.
				' (SELECT d.id FROM #__categories AS d WHERE d.id=c.catid) as article_id , '.
				' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.alias) ELSE a.id END as slug, '.
				' CASE WHEN CHAR_LENGTH(b.alias) THEN CONCAT_WS(\':\', b.id, b.alias) ELSE b.id END as catslug, '.
				' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as article_slug ';
        $from   = '#__nbeventmap AS a';
		$joins[] = 'INNER JOIN #__categories AS b on a.catid = b.id';
		$joins[] = 'LEFT OUTER JOIN #__content AS c on a.article_id = c.id';

		$wheres[] = 'a.published = 1';

		$user =& JFactory::getUser();
		$aid = $user->get('aid', 0);
		

		$query = "SELECT " . $select .
				"\n FROM " . $from .
				"\n " . implode ( ' ', $joins ) .
				"\n WHERE " . implode( "\n  AND ", $wheres );

		return $query;
	}
	
	function getNBEventMapList( $options=array() )
	{
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 

		if (empty($this->_result2))
		{
			$query	= $this->_getQuery( $options );
			$this->_result2 = $this->_getList( $query );

			$file = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php';
			if(file_exists($file)) {
			
				$search_nbeventmap = $mainframe->getUserStateFromRequest( $option.$Itemid.'search_nbeventmap', 'search_nbeventmap', '',    'string' );
				$search_nbeventmap = JString::strtolower($search_nbeventmap);
				if ($search_nbeventmap) {
					$Resultat_filtre = array();
					foreach ($this->_result2 as $result) {
						if ((!(strpos(JString::strtolower($result->nom),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->intro),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->message),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse2),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->ville),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->departement),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->pay),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->email),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->web),$search_nbeventmap)===false))) {
							$Resultat_filtre[] = $result;
						}
					};
					$this->_result2=$Resultat_filtre;
				}
			};
		}
		
		
		
		return @$this->_result2;
	}
	
	function getView()
	{
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
		
		if (empty($this->_result)) {
			$query 	= $this->_getQuery();
			$this->_result = $this->_getList( $query );
			
			$query 	= $this->_getQuery_orderA();
			$this->_result_orderA = $this->_getList( $query );

			
			$file = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'joomfish.php';
			if(file_exists($file)) {
			
				$search_nbeventmap = $mainframe->getUserStateFromRequest( $option.$Itemid.'search_nbeventmap', 'search_nbeventmap', '',    'string' );
				$search_nbeventmap = JString::strtolower($search_nbeventmap);
				if ($search_nbeventmap) {
					$Resultat_filtre = array();
					foreach ($this->_result as $result) {
						if ((!(strpos(JString::strtolower($result->nom),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->intro),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->message),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse2),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->ville),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->departement),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->pay),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->email),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->web),$search_nbeventmap)===false))) {
							$Resultat_filtre[] = $result;
						}
					};
					$this->_result=$Resultat_filtre;
					
					$Resultat_filtre_orderA = array();
					foreach ($this->_result_orderA as $result) {
						if ((!(strpos(JString::strtolower($result->nom),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->intro),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->message),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->adresse2),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->ville),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->departement),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->pay),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->email),$search_nbeventmap)===false)or!(strpos(JString::strtolower($result->web),$search_nbeventmap)===false))) {
							$Resultat_filtre_orderA[] = $result;
						}
					};
					$this->_result_orderA=$Resultat_filtre_orderA;
				}
			};
		};
		if ($this->_result) {
			$map	= $this->getCarte($this->_result, $this->_result_orderA, 0, 0, 0, $num_temp);
		}else{
			$map	= JText::_('NBEVENTMAP_AUCUNE_INFO')."</br></br>";
		};
		return $map;
	}

	
	function getViewPlugin($ids, $num, $Hmap='0', $Lmap='0', $Zmap='0', $Itin='0', $bar_PSM='0', $bar_z_nav='0', $Ech='0', $click_over='0', $MZoom='0', $ZZoom='0', $map_phy='0', $map_nor='0', $map_sat='0', $map_hyb='0', $map_choix='0', $kml_file='0', $map_earth='0', $map_centre_lng='0', $map_centre_lat='0', $plugcatids, $More='0', $map_centre_id='0')
	{
		
		
		if ($map_centre_id!=0) {
			$map_centre_ids[]=$map_centre_id;
			$query 	= $this->_getQueryPlugin($map_centre_ids);
			$result = $this->_getList( $query );
			$map_centre_lng = $result[0]->glng;
			$map_centre_lat = $result[0]->glat;
			if ($Zmap==0) {
				$Zmap = $result[0]->gzoom;
			};
		}

		
		if ($ids!=0) {
			$query 	= $this->_getQueryPlugin($ids);
			$result = $this->_getList( $query );
			foreach($result as $lieu) {
				$rows[] = $lieu;
			};
		}

		
        if ($plugcatids!=0) {
			$catids = array();
			foreach ($plugcatids as $plugcatid) {
				$catids = array_merge($catids, $this->verif_catid($plugcatid));
			};
        }else{
			$catids=0;
		};

		
		if ($catids!=0) {
			$query 	= $this->_getQueryPluginCatid($catids);
			$result = $this->_getList( $query );
			foreach($result as $lieu) {
				$rows[] = $lieu;
			};
		}
		
		
		if (!(@$rows)) {
			$language =& JFactory::getLanguage();
			$language->load('com_nbeventmap');
			JError::raiseWarning(0, JText::_('NBEVENTMAP_MAUVAIS_ID_PLUGIN'));
			return(JText::_('NBEVENTMAP_MAUVAIS_ID_PLUGIN'));
		}else{
			
			$rows_orderA = $rows;
			foreach ($rows_orderA as $row) {
				$rows_orderA_id[]=$row->id;
				$rows_orderA_nom[]=$row->nom;
			}
			$array_lowercase = array_map('strtolower', $rows_orderA_nom);
			array_multisort($array_lowercase, SORT_ASC,  $rows_orderA_id, SORT_ASC, $rows_orderA);
			

		
		$map	= $this->getCarte($rows, $rows_orderA, $map_centre_lat, $map_centre_lng, 1, $num, $Hmap, $Lmap, $Zmap, $Itin, $bar_PSM, $bar_z_nav, $Ech, $click_over, $MZoom, $ZZoom, $map_phy, $map_nor, $map_sat, $map_hyb, $map_choix, $kml_file, $map_earth, $More);
	return $map;
		};
	}
	
	function getCarte ($rows, $rows_orderA, $glat_plugin, $glng_plugin, $plugin, $num, $Hmap = '', $Lmap = '', $Zmap = '',  $Itin='0', $bar_PSM='0', $bar_z_nav='0', $Ech='0', $click_over='0', $MZoom='0', $ZZoom='0', $map_phy='0', $map_nor='0', $map_sat='0', $map_hyb='0', $map_choix='0', $kml_file='0', $map_earth='0', $More='0')
	{
		
	$mainframe = &JFactory::getApplication(); 
	$language =& JFactory::getLanguage();
	$language->load('com_nbeventmap');
	$config =& JComponentHelper::getParams('com_nbeventmap');
	$perso = $this->getPersonnalisation();
	$doc =& JFactory::getDocument();

	$xml_files = explode(";",$config->get('nbeventmap_geoXML'));

	
    $_layout = JRequest::getVar('layout', "", '', 'str'); 
	$zoom = "";
	if ($_layout == "item_carte") {
		if ((empty($this->_id))or($config->get('nbeventmap_zoom_lightbox_carte')!=100)) {
			$zoom =	$config->get('nbeventmap_zoom_lightbox_carte');
		}else{
			$zoom = $rows[0]->gzoom;
		};
	};
	if ($_layout == "print_article") {
		$zoom =	$config->get('nbeventmap_zoom_lightbox_imprimer');
	};
	if (($zoom == "") or ($zoom == 0)) {
		$zoom = $config->get('nbeventmap_zoom');
	};
	if (!($zoom)) { $zoom = 2;};
	if (!($Zmap)) {
		$Zmap = $zoom;
	};

	$flag = JRequest::getVar('flag', 0, '0', 'int');
	if ($plugin==1) {$layout = 'carte';};
	$itemid = JRequest::getVar('Itemid', 0, '', 'int');

	if (empty($num)) { $num = ''; };

		if (($config->get('nbeventmap_plus_detail')==0)||($flag==1)) {
            if (((($config->get('nbeventmap_eventcontrol')==1)OR($config->get('nbeventmap_eventcontrol')==2))AND($click_over==0))OR($click_over==1)){
				$carte='marker[i] = new GMarker(point, markerOptions);
				GEvent.addListener(marker[i], "mouseover", function() {
					marker[i].openInfoWindowHtml(html);
				});
				';
                if ($config->get('nbeventmap_eventcontrol')==1)
				$carte.='
				GEvent.addListener(marker, "mouseout", function() {
					marker.closeInfoWindow();
				}); ';
			}else{
				
				$carte='marker[i] = new GMarker(point, markerOptions);
				GEvent.addListener(marker[i], "mousedown", function() {
					marker[i].openInfoWindowHtml(html);
				}); ';
			};
		}else{
			if (!($config->get('nbeventmap_largeur_lightbox'))) {$largeur_lightbox=700;} else {$largeur_lightbox=$config->get('nbeventmap_largeur_lightbox');};
			if (!($config->get('nbeventmap_hauteur_lightbox'))) {$hauteur_lightbox=400;} else {$hauteur_lightbox=$config->get('nbeventmap_hauteur_lightbox');};
            if (((($config->get('nbeventmap_eventcontrol')==1)OR($config->get('nbeventmap_eventcontrol')==2))AND($click_over==0))OR($click_over==1)){
				$carte='marker[i] = new GMarker(point, markerOptions);
				GEvent.addListener(marker[i], "mouseover", function() {
					marker[i].openInfoWindowHtml(html);
				});
				';
                if ($config->get('nbeventmap_eventcontrol')==1)
				$carte.='
				GEvent.addListener(marker[i], "mouseout", function() {
					marker[i].closeInfoWindow();
				});
				';
				$carte.='
				GEvent.addListener(marker[i], "mousedown", function() {';
			}else{

				$carte='marker[i] = new GMarker(point, markerOptions);
				GEvent.addListener(marker[i], "mousedown", function() {';
			};

			switch ($config->get('target'))
			{
				case 1:
									
					
					$carte.= 'parent.location=id';
					break;
				case 2:
					
					
					$carte.= "window.open(id, title_value, 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=".$largeur_lightbox.",height=".$hauteur_lightbox."'); ";
					break;
				case 3:
					
					
					$carte.= "window.open(id, title_value, 'toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=".$largeur_lightbox.",height=".$hauteur_lightbox."');";
					break;
				default:
					
					
					$carte.='fb.start({ href: id, rev: "width:'.$largeur_lightbox.' height:'.$hauteur_lightbox.' scrolling:yes innerBorder:1" });';
					break;
			}

			$carte.='}); ';
		};

	$CustomHeadTag1=( ' 
		var baseIcon = new GIcon();
	
		function tailleMarker'.$num.'(hm,lm) {
			baseIcon.iconSize = new GSize(lm,hm);
			baseIcon.shadowSize = new GSize(lm*1.5,hm*1);
			baseIcon.iconAnchor = new GPoint((lm/2),hm);
			baseIcon.infoWindowAnchor = new GPoint((lm/2),0);
			baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
			baseIcon.imageMap=[0,0,lm,0,lm,hm,0,hm];
		}
			
        var nnn'.$num.' = 99999;    
        
        function fixOrder'.$num.'(){
			//return nnn'.$num.'--;
			return setTimeout("fixorder2'.$num.'()",0);
        }
        function fixorder2'.$num.'(){
			return nnn'.$num.'--;
		}
				
		function createMarker'.$num.'(i,point,html,marqueur,id,choix,title_value) {
			var letteredIcon = new GIcon(baseIcon,marqueur);
			letteredIcon.transparent = marqueur;
			markerOptions = { icon:letteredIcon, title:title_value, zIndexProcess:fixOrder'.$num.' };
			'.$carte.'
		}
	');

	$plus_infos='	var map'.$num.';
			var marker = [];
			var bounds'.$num.' = null; 
			bounds'.$num.' = new GLatLngBounds(); 
	';
	
	$plus_infos.=$CustomHeadTag1;

	

	if ((($config->get('nbeventmap_plus_info')==1)AND($More==0))OR($More==1)){
		$doc->addCustomTag( '
			<style type="text/css"> 
				 
				#more_inner_nbeventmap'.$num.' {
					text-align:center;
					font-size:12px;
					background-color: #fff;
					color: #000;
					border: 1px solid #fff;
					border-right-color: #b0b0b0;
					border-bottom-color: #c0c0c0;
					cursor: pointer;
				}
				 
				#more_inner_nbeventmap'.$num.'.highlight {
					font-weight: bold;
					border: 1px solid #483D8B;
					border-right-color: #6495ed;
					border-bottom-color: #6495ed;
				}
				 
				#box_nbeventmap'.$num.' {  position:absolute;
					top:20px; left:0px;
					margin-top:-1px;
					font-size:12px;
					padding: 6px 4px;
					width:120px;
					background-color: #fff;
					color: #000;
					border: 1px solid gray;
					border-top:1px solid #e2e2e2;
					display: none;
					cursor:default;
				}
				 
				#box_nbeventmap'.$num.'.highlight {
					width:119px;
					border-width:2px;
				}
				 
			</style> 
			');
			

		$plus_infos.='
			var timer'.$num.';
			var chosen_nbeventmap'.$num.' = [];

			var layers_nbeventmap'.$num.' = [
			 { name: "Pano", obj: new GLayer("com.panoramio.all") },
			 { name: "Tube", obj: new GLayer("com.youtube.all") },
			 { name: "Wiki", obj: new GLayer("'.$config->get('nbeventmap_url_wiki').'") },
			 { name: "Cams", obj: new GLayer("com.google.webcams") }
			];

			function hideAll_nbeventmap'.$num.'() {
			 var boxes = document.getElementsByName("mark_nbeventmap'.$num.'");
			 for(var i = 0; i < boxes.length; i++) {
			  if(boxes[i].checked) {
			   boxes[i].checked = false;
			   switchLayer_nbeventmap'.$num.'(false, layers_nbeventmap'.$num.'[i].obj);
			   chosen_nbeventmap'.$num.'.push(i);
			  }
			 }
			}
			 
			function checkChecked_nbeventmap'.$num.'() {
			 /* Returns true if a checkbox is still checked
			 *  otherwise false
			 */
			 var boxes = document.getElementsByName("mark_nbeventmap'.$num.'");
			 for(var i = 0; i < boxes.length; i++) {
			  if(boxes[i].checked) return true;
			 }
			 return false;
			}
			 
			function switchLayer_nbeventmap'.$num.'(checked, layer) {
			 var layerbox = document.getElementById("box_nbeventmap'.$num.'");
			 var boxlink = document.getElementById("boxlink_nbeventmap'.$num.'");
			 var button = document.getElementById("more_inner_nbeventmap'.$num.'");
			 if(checked) {
			    map'.$num.'.addOverlay(layer);
			   // Reset chosen array
			   chosen_nbeventmap'.$num.'.length = 0;
			   /* Highlight the link and
			   *  make the button font bold.
			   */
			   boxlink.className ="highlight";
			   layerbox.className ="highlight";
			   button.className ="highlight";
			 }
			 else {
			   map'.$num.'.removeOverlay(layer);
			   /*  Reset the link and the button
				* if all checkboxes were unchecked.
			   */
			   if(!checkChecked_nbeventmap'.$num.'()) {
				boxlink.blur();
				boxlink.className ="";
				layerbox.className ="";
				button.className ="";
			   }
			 }
			}
			 
			function showLayerbox_nbeventmap'.$num.'() {
			 if(window.timer'.$num.') clearTimeout(timer'.$num.');
			 document.getElementById("box_nbeventmap'.$num.'").style.display = "block";
			 var button = document.getElementById("more_inner_nbeventmap'.$num.'");
			 button.style.borderBottomWidth = "4px";
			 button.style.borderBottomColor = "white";
			}
			 
			function setClose_nbeventmap'.$num.'() {
			 var layerbox = document.getElementById("box_nbeventmap'.$num.'");
			 var button = document.getElementById("more_inner_nbeventmap'.$num.'");
			 var bottomColor = checkChecked_nbeventmap'.$num.'() ? "#6495ed" : "#c0c0c0";
			 timer'.$num.' = window.setTimeout(function() {
			  layerbox.style.display = "none";
			  button.style.borderBottomWidth = "1px";
			  button.style.borderBottomColor = bottomColor;
			 }, 400);
			}
			 
			//appui sur le bouton "plus" 
			function toggleLayers_nbeventmap'.$num.'() {
			 if(chosen_nbeventmap'.$num.'.length > 0 ) {
			   /* Make an independent copy of chosen array since switchLayer()
			   *  resets the chosen array, which may not be useful here.
			   */
			   var copy = chosen_nbeventmap'.$num.'.slice();
			   for(var i = 0; i < copy.length; i++) {
				var index = parseInt(copy[i]);
				switchLayer_nbeventmap'.$num.'(true, layers_nbeventmap'.$num.'[index].obj);
				document.getElementsByName("mark_nbeventmap'.$num.'")[index].checked = true;
			   }
			 }
			 else {
			  hideAll_nbeventmap'.$num.'();
			 }
			}
			 
			function MoreControl_nbeventmap'.$num.'() {};
			MoreControl_nbeventmap'.$num.'.prototype = new GControl();

			MoreControl_nbeventmap'.$num.'.prototype.initialize = function(map'.$num.') {
			 var more = document.getElementById("outer_more_nbeventmap'.$num.'");
			 var buttonDiv = document.createElement("div");
			 buttonDiv.id = "morebutton";
			 buttonDiv.title = "Show/Hide Layers";
			 buttonDiv.style.border = "1px solid black";
			 buttonDiv.style.width = "86px";
			 var textDiv = document.createElement("div");
			 textDiv.id = "more_inner_nbeventmap'.$num.'";
			 textDiv.appendChild(document.createTextNode("'.JText::_('NBEVENTMAP_MORE').'..."));
			 buttonDiv.appendChild(textDiv);
			 
			 // Register Event handlers
			 more.onmouseover = showLayerbox_nbeventmap'.$num.';
			 more.onmouseout = setClose_nbeventmap'.$num.';
			 buttonDiv.onclick = toggleLayers_nbeventmap'.$num.';
			 
			 // Insert the button just after outer_more div
			 more.insertBefore(buttonDiv, document.getElementById("box_nbeventmap'.$num.'").parentNode);
			 // Remove the whole div from its location and reinsert it to the map
			 map'.$num.'.getContainer().appendChild(more);
			 return more;
			};
			 
			MoreControl_nbeventmap'.$num.'.prototype.getDefaultPosition = function() {
			 return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 30));
			};
'; };

	$carte="\n";
	

	if ((($config->get('nbeventmap_mapcontrol')==1)AND($bar_z_nav==0))OR($bar_z_nav==1)) 
		{ $carte.='map'.$num.'.addControl(new GLargeMapControl3D()); ';};
	if ((($config->get('nbeventmap_scalecontrol')==1)AND($Ech==0))OR($Ech==1)) 
		{ $carte.='map'.$num.'.addControl(new GScaleControl()); ';
		};


	$compt = 0;
	foreach ($xml_files as $xml_file) {
		$carte.= '
		map'.$num.'.addOverlay(geoXML'.$num.'_'.$compt.'); ';
		$compt ++;
	};	
	if ($kml_file) { $carte.= '
		map'.$num.'.addOverlay(geoXML'.$num.'); ';};


	if ((($config->get('nbeventmap_plus_info')==1)AND($More==0))OR($More==1)){
		$carte.='
		map'.$num.'.addControl(new MoreControl_nbeventmap'.$num.'());';
	};
	

	if ((($config->get('nbeventmap_earth')==1)AND($map_earth==0))OR($map_earth==1)) 
		{ $carte.='
		map'.$num.'.addMapType(G_SATELLITE_3D_MAP); ';};

		$carte.='
		var customUI'.$num.'=map'.$num.'.getDefaultUI();';

		$carte.='
		customUI'.$num.'.controls.maptypecontrol=true;';

	if ((($config->get('nbeventmap_hybrid')==1)AND($map_hyb==0))OR($map_hyb==1)) 
		{ $carte.='
		customUI'.$num.'.maptypes.hybrid=true; ';}
	else
		{ $carte.='
		customUI'.$num.'.maptypes.hybrid=false; ';};

	if ((($config->get('nbeventmap_normal')==1)AND($map_nor==0))OR($map_nor==1)) 
		{ $carte.='
		customUI'.$num.'.maptypes.normal=true; ';}
	else
		{ $carte.='
		customUI'.$num.'.maptypes.normal=false; ';};

	if ((($config->get('nbeventmap_physic')==1)AND($map_phy==0))OR($map_phy==1)) 
		{ $carte.='
		customUI'.$num.'.maptypes.physical=true; ';}
	else
		{ $carte.='
		customUI'.$num.'.maptypes.physical=false; ';};

	if ((($config->get('nbeventmap_satellite')==1)AND($map_sat==0))OR($map_sat==1)) 
		{ $carte.='
		customUI'.$num.'.maptypes.satellite=true; ';}
	else
		{ $carte.='
		customUI'.$num.'.maptypes.satellite=false; ';};


	if ((($config->get('nbeventmap_mousewheel')==1)AND($MZoom==0))OR($MZoom==1)) 
		{ $carte.='
		customUI'.$num.'.zoom.scrollwheel=true;';}
	else
		{ $carte.='
		customUI'.$num.'.zoom.scrollwheel=false;';};

	if ((($config->get('nbeventmap_zzoom')==1)AND($ZZoom==0))OR($ZZoom==1)) 
		{ $carte.='
		customUI'.$num.'.controls.overviewmapcontrol=true;';}
	else
		{ $carte.='
		customUI'.$num.'.controls.overviewmapcontrol=false;';};
	$carte.='
	customUI'.$num.'.controls.smallzoomcontrol3d=false;';

	$carte.='
		map'.$num.'.setUI(customUI'.$num.');';

	$carte.="\n\n";
	$points = "";
	$cesure = $config->get('nbeventmap_taille_bulle_cesure');
	$plus_detail = "";
	if ((($config->get('type_affichage')==1)||($flag!=1))&&($config->get('nbeventmap_plus_detail')==1)) { $plus_detail = "<h4>".JText::_('NBEVENTMAP_CLIQUER_POUR_ARTICLE')."</h4>"; };
	$cnt2 = 1;
	
	foreach($rows as $row){
		$points.='tailleMarker'.$num.'(markerImage'.$cnt2.'.height,markerImage'.$cnt2.'.width);';
		$cnt2++;

		if (($row->glat<>"")&&($row->glng<>"")) {
			$image ='';
			if (@$row->img) {
				$image = JURI::base().$config->get('nbeventmap_chemin_img').$row->img;
				$image = "<img src=".$image." height=".$config->get('nbeventmap_hauteur_img')."px>";
			}
			$points.= 'var point = new GLatLng('.$row->glat.','.$row->glng.'); ';
			
            if (@$row->intro) {$intro=trim($row->intro);}else{$intro='';};
            $intro = str_replace(chr(10), '',$intro);
            $intro = str_replace(chr(13), '<BR />',$intro);
            if (@$row->message) {$message=trim($row->message);}else{$message='';};
            $message = str_replace(chr(10), '',$message);
            $message = str_replace(chr(13), '<BR />',$message);
			
			if ($config->get('nbeventmap_html_bubble')){ 
                $text = addslashes($intro.$message);
            }else{
                $text = strip_tags(addslashes($intro.$message),"<BR>");
            }
			
			$nom  = addslashes(trim($row->nom));
			
			$link4=substr(trim($row->link),0,4);
			$link5=substr(trim($row->link),0,5);
			$link9=substr(trim($row->link),0,9);
			$linkmap=trim($row->link);
			
			if ($link4=="www.") {$linkmap="http://".$linkmap;};
			
			if ((empty($row->link))||($row->link='')) {
				if ($config->get('target')==0) {
					$map_link=JRoute::_('index.php?option=com_nbeventmap&view=nbeventmap&Itemid='.$itemid.'&layout=article&tmpl=component&id='.$row->id, false);
				}else{
					$map_link=JRoute::_('index.php?option=com_nbeventmap&view=nbeventmap&Itemid='.$itemid.'&layout=article&id='.$row->slug, false);
				};
				$choix=1;
			} else {
				if (($link5=="http:")||($link4=="www.")||($link9=="index.php")) {
					$map_link=$linkmap;
					if (($link5=="http:")||($link4=="www.")) {$choix=0;}else{$choix=1;};
				} else {
					if(!class_exists('ContentHelperRoute')) require_once (JPATH_SITE . '/components/com_content/helpers/route.php');  
					if ($config->get('target')==0) {
						
						$map_link=JRoute::_(ContentHelperRoute::getArticleRoute($row->article_slug, $row->article_id.':'.$row->article_alias, 0));
						$map_link .= '?&tmpl=component';
					}else{
						
						
						$map_link=JRoute::_(ContentHelperRoute::getArticleRoute($row->article_slug, $row->article_id.':'.$row->article_alias, 0));
					};
					$choix=1;
				};
			};
			if (@$row->icon)	{
				if($config->get('target')==0) {
					$map_link=JRoute::_('index.php?option=com_nbeventmap&view=nbeventmap&Itemid='.$itemid.'&layout=article&tmpl=component&id='.$row->id, false);
				}else{
					$map_link=JRoute::_('index.php?option=com_nbeventmap&view=nbeventmap&Itemid='.$itemid.'&layout=article&id='.$row->slug, false);
				};
			};
			
			if (@$row->ville) 	{$citys 	= addslashes(trim($row->ville)).", ";}else{$citys='';};
			if (@$row->pay) 	{$countrys 	= addslashes(trim($row->pay));}else{$countrys='';};
			if (@$row->intro) 	{$descriptions 	= addslashes(trim($row->intro));}else{$descriptions='';};
			if (@$row->start_date) 	{$start_dates 	= $row->start_date;}else{$start_dates='';};
			if (@$row->end_date) 	{$end_dates 	= $row->end_date;}else{$end_dates='';};

			if (@$row->adresse) 	{$adr 	= addslashes(trim($row->adresse))."<br />";}else{$adr='';};
			if (@$row->adresse2) 	{$adr2 	= addslashes(trim($row->adresse2))."<br />";}else{$adr2='';};
			if (@$row->codepostal) 	{$cp 	= addslashes(trim($row->codepostal))."<br />";}else{$cp='';};
			if (@$row->ville) 		{$ville = addslashes(trim($row->ville))."<br />";}else{$ville='';};
			if (@$row->departement) {$dep 	= addslashes(trim($row->departement))."<br />";}else{$dep='';};
			if (@$row->pay) 		{$pays 	= addslashes(trim($row->pay))."<br />";}else{$pays='';};
			
			$height_bubble = $config->get('nbeventmap_height_bulle_NBEventMap', '150px');
			if ((substr($height_bubble, -1)!="%")and(strtolower(substr($height_bubble, -2)!="px"))) {$height_bubble .= "px";};
			
			switch ($row->affichage) {
			case 0:	
				$nom = $citys . $countrys;
				$date_popup = date("d-M-Y",strtotime($start_dates)) . ' to ' . date("d-M-Y",strtotime($end_dates));
				$points.= "createMarker".$num."(".$this->_num_marqueurs.", point, \"<div class='nbeventmap_marqueur' style='width:".$config->get('nbeventmap_width_bulle_NBEventMap')."px; height:".$height_bubble."; overflow:auto'><span>".$nom."</span><br /><br />".$image."<table><table><tr><td class='text_popups'>".substr($text,0,$cesure)."..."."</td></tr></table><tr><td>".'<br>'."<div class='text_date_popups'>".$date_popup."</div>";
				if (strlen($text)>$cesure) { $points.=""; };
				$points.="</td></tr></table><br /></div>".$plus_detail."<br />\",'".$row->marqueur."',\"".$map_link."\",".$choix;
				break;
			case 1:
				$points.= "createMarker".$num."(".$this->_num_marqueurs.", point, \"<div class='nbeventmap_marqueur' style='width:".$config->get('nbeventmap_width_bulle_NBEventMap')."px; height:".$height_bubble."; overflow:auto'><span>".$nom."</span><br /><br />".$image."<table><tr><td>".$adr.$adr2.$cp.$ville.$dep.$pays."</td></tr></table><br /></div>".$plus_detail."<br />\",'".$row->marqueur."',\"".$map_link."\",".$choix;
				break;
			case 2:
				
				$points.= "createMarker".$num."(".$this->_num_marqueurs.", point, \"<div class='nbeventmap_marqueur' style='width:".$config->get('nbeventmap_width_bulle_NBEventMap')."px; height:".$height_bubble."; overflow:auto';><span>".$nom."</span><br /><br />".$image.substr($text,0,$cesure);
				if (strlen($text)>$cesure) { $points.="..."; };
				$points.="<br /></div>".$plus_detail."<br />\",'".$row->marqueur."',\"".$map_link."\",".$choix;
				break;
			default:
				
				$points.= "createMarker".$num."(".$this->_num_marqueurs.", point, \"<div class='nbeventmap_marqueur' style='width:".$config->get('nbeventmap_width_bulle_NBEventMap')."px; height:".$height_bubble."; overflow:auto';><span>".$nom."</span>";
				$points.="<br /></div>".$plus_detail."<br />\",'".$row->marqueur."',\"".$map_link."\",".$choix;
			}
			if (!((($config->get('nbeventmap_eventcontrol')==1)AND($click_over==0))OR($click_over==1))){
				$points.=", \"".$nom."\"";
			};			
			$points.="); map".$num.".addOverlay(marker[".$this->_num_marqueurs."]);";
			$points.="bounds".$num.".extend(point);\n\n";

			$this->_num_marqueurs++;
		}
	}
	$carte.=''.$points.'';
	
	if ($plugin) {
		if (($glat_plugin)and($glng_plugin)) {
			$carte.='map'.$num.'.setCenter(new GLatLng('.$glat_plugin.','.$glng_plugin.'),'.$Zmap.'); ';
		}else{
			if ($Zmap) {
				$carte.='map'.$num.'.setCenter(bounds'.$num.'.getCenter(),'.$Zmap.'); ';
			}else{
				$carte.='map'.$num.'.setCenter(bounds'.$num.'.getCenter(), map'.$num.'.getBoundsZoomLevel(bounds'.$num.')); ';
			}
		};
	}else{
		
		if (($config->get('nbeventmap_auto')==0)and($config->get('nbeventmap_auto_zoom')==0)) {
			$carte.='map'.$num.'.setCenter(new GLatLng('.$config->get('nbeventmap_centre_lat').','.$config->get('nbeventmap_centre_lng').'),'.$Zmap.'); ';
		}else{
			if ($config->get('nbeventmap_auto_zoom')==0) {
				$carte.='map'.$num.'.setCenter(bounds'.$num.'.getCenter(),'.$Zmap.'); ';
			}else{
				$carte.='map'.$num.'.setCenter(bounds'.$num.'.getCenter(), map'.$num.'.getBoundsZoomLevel(bounds'.$num.')); ';
			}
		};
	};
	
	if ($map_choix==0) {
		$carte_choix='G_NORMAL_MAP';
		if ($config->get('nbeventmap_choix_affichage_carte')==2) { $carte_choix='G_SATELLITE_MAP';};
		if ($config->get('nbeventmap_choix_affichage_carte')==3) { $carte_choix='G_HYBRID_MAP';};
		if ($config->get('nbeventmap_choix_affichage_carte')==4) { $carte_choix='G_PHYSICAL_MAP';};
		if ($config->get('nbeventmap_choix_affichage_carte')==5) { $carte_choix='G_SATELLITE_3D_MAP';};
	} else {
		$carte_choix='G_NORMAL_MAP';
		if ($map_choix==2) { $carte_choix='G_SATELLITE_MAP';};
		if ($map_choix==3) { $carte_choix='G_HYBRID_MAP';};
		if ($map_choix==4) { $carte_choix='G_PHYSICAL_MAP';};	
		if ($map_choix==5) { $carte_choix='G_SATELLITE_3D_MAP';};	
	}
	$geo_xml='';
	$compt = 0;
	foreach ($xml_files as $xml_file) {
		$geo_xml.= '
		geoXML'.$num.'_'.$compt.' = new GGeoXml("'.$xml_file.'");'."\n";
		$compt ++;
	};	
	if ($kml_file) {
		$geo_xml.= 'geoXML'.$num.' = new GGeoXml("'.$kml_file.'");
		';
	};	
	$gestion_erreur_direction='';
	if ((($config->get('nbeventmap_itineraire')==1)AND($Itin==0))OR($Itin==1)) {
		$gestion_erreur_direction='GEvent.addListener(gdir'.$num.', "error", handleErrors'.$num.');';
	};
	
	
    $doc->addCustomTag( '<script type="text/javascript"> 
		'.$plus_infos.'
		function initializeGmapFP'.$num.'() {'.
			$geo_xml.'
			map'.$num.' = new GMap2(document.getElementById("map'.$num.'"),{mapTypes:['.$carte_choix.']});
			gdir'.$num.' = new GDirections(map'.$num.', document.getElementById("nbeventmap_directions'.$num.'"));
			'
			.$gestion_erreur_direction
			.$carte.'
		}
		function handleErrors'.$num.'(){
	    	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     		alert("'.JText::_( 'NBEVENTMAP_G_GEO_UNKNOWN_ADDRESS' ).'\n'.JText::_( 'NBEVENTMAP_CODE_ERREUR' ).' " + gdir.getStatus().code);
	   		else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     		alert("'.JText::_( 'NBEVENTMAP_G_GEO_SERVER_ERROR' ).'\n'.JText::_( 'NBEVENTMAP_CODE_ERREUR' ).' " + gdir.getStatus().code);
	   		else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     		alert("'.JText::_( 'NBEVENTMAP_G_GEO_MISSING_QUERY' ).'\n'.JText::_( 'NBEVENTMAP_CODE_ERREUR' ).' " + gdir.getStatus().code);
	   		else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     		alert("'.JText::_( 'NBEVENTMAP_G_GEO_BAD_KEY' ).'\n'.JText::_( 'NBEVENTMAP_CODE_ERREUR' ).' " + gdir.getStatus().code);
	   		else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     		alert("'.JText::_( 'NBEVENTMAP_G_GEO_BAD_REQUEST' ).'\n'.JText::_( 'NBEVENTMAP_CODE_ERREUR' ).' " + gdir.getStatus().code);
	   		else alert("'.JText::_( 'NBEVENTMAP_G_GEO_ELSE' ).'");
		}
        </script>'); 
	
	if (empty($Hmap)) {$Hmap=$config->get('nbeventmap_height');};
	if (empty($Lmap)) {
		if ((strpos($config->get('nbeventmap_width'),'%'))or(strpos($config->get('nbeventmap_width'),'x'))){
			$Lmap=$config->get('nbeventmap_width');
		}else{
			$Lmap=$config->get('nbeventmap_width').'px';
		};
	};
	$carte='';
	if (!empty($perso)) { 
		
		$dispatcher =& JDispatcher::getInstance(); 
		JPluginHelper::importPlugin('content'); 
		if (!empty($perso->intro_carte)) { 
			$article->text=$perso->intro_carte; 
			$results = $dispatcher->trigger('onPrepareContent', array (& $article, & $this->params, 0)); 
			$carte.=$article->text;
		};
	};	
	$carte.=
	'<div id="nbeventmap" style="width:'.$Lmap.'; height:auto; overflow:hidden;">';
	$carte.=
		'<div id="map'.$num.'" style="width:'.$Lmap.'; height:'.$Hmap.'px"></div>';

	
	
	

	if ((($config->get('nbeventmap_plus_info')==1)AND($More==0))OR($More==1)){
		$carte.='
			<div id="outer_more_nbeventmap'.$num.'"> 
			<form action=""> 
			<div id="box_nbeventmap'.$num.'">  
			<input name="mark_nbeventmap'.$num.'" type="checkbox" onclick="switchLayer_nbeventmap'.$num.'(this.checked, layers_nbeventmap'.$num.'[0].obj)" /> Photos <br /> 
			<input name="mark_nbeventmap'.$num.'" type="checkbox" onclick="switchLayer_nbeventmap'.$num.'(this.checked, layers_nbeventmap'.$num.'[1].obj)" /> Videos <br /> 
			<input name="mark_nbeventmap'.$num.'" type="checkbox" onclick="switchLayer_nbeventmap'.$num.'(this.checked, layers_nbeventmap'.$num.'[2].obj)" /> Wikipedia <br /> 
			<input name="mark_nbeventmap'.$num.'" type="checkbox" onclick="switchLayer_nbeventmap'.$num.'(this.checked, layers_nbeventmap'.$num.'[3].obj)" /> Webcams
			<hr style="width:92%;height:1px;border:1px;color:#e2e2e2;background-color:#e2e2e2;" /> 
			<a id="boxlink_nbeventmap'.$num.'" href="javascript:void(0)" onclick="hideAll_nbeventmap'.$num.'()">'.JText::_('NBEVENTMAP_HIDE_ALL').'</a> 
			</div></form> 
			</div> 
			';
	};
	$carte.='</div>';

			if (!empty($perso->conclusion_carte)) { 
				$article->text=$perso->conclusion_carte; 
				$results = $dispatcher->trigger('onPrepareContent', array (& $article, & $this->params, 0)); 
				$carte.=$article->text;
			};
			
	$carte.='<div>';
			
			
	if ((($config->get('nbeventmap_itineraire')==1)AND($Itin==0))OR($Itin==1)) {
			$carte.='					
				<p style="text-align:center;margin:2px 0;">&nbsp;</p>
				<form action="#" onsubmit="setDirections(\''.$num.'\'); return false;" method="post" name="direction_form">
						<div class="gmnoprint">
						
						<p>
							
							<select name="select_from'.$num.'" id="select_from'.$num.'">
								<option value="">'.JText::_( 'NBEVENTMAP_CHOIX_DE' ).'</option>';
								foreach($rows_orderA as $row) {
									$selected = '';
									if (isset($row->glat) && isset($row->glng) && !empty($row->glat) && !empty($row->glng)) {
										$value = $row->glat.','.$row->glng;
									} else {
										$value = @$row->pay.' '.@$row->codepostal.' '.@$row->ville.' '.@$row->adresse.' '.@$row->adresse2;
									}
									$carte .= '<option value="'.$value.'" '.$selected.'>'.$row->nom.'</option>';
								}
								$carte.='
							</select>
							
						</p>
							
							<select name="select_to'.$num.'" id="select_to'.$num.'">
								<option value="">'.JText::_( 'NBEVENTMAP_CHOIX_VERS' ).'</option>';
								foreach($rows_orderA as $row) {
									$selected = '';
									if (isset($row->glat) && isset($row->glng) && !empty($row->glat) && !empty($row->glng)) {
										$value = $row->glat.','.$row->glng;
									} else {
										$value = @$row->pay.' '.@$row->codepostal.' '.@$row->ville.' '.@$row->adresse.' '.@$row->adresse2;
									}
									$carte .= '<option value="'.$value.'" '.$selected.'>'.$row->nom.'</option>';
								}
								$carte.='
							</select>
							
						
						</div>
						
				<input type="hidden" name="direction" value="1" />
				</form>
				';
			};
	$carte.='</div>';	
			
	$loadmarqueur = '';
	$cnt = 1;
	foreach($rows as $row) {
		$loadmarqueur .=" markerImage".$cnt." = new Image(); ";
		$loadmarqueur .=" markerImage".$cnt.".src = \"".$row->marqueur."\";\n ";
		$cnt++;
	}	
    $doc->addCustomTag( '<script type="text/javascript">//<![CDATA[
		function generic() {
			setTimeout("initializeGmapFP'.$num.'()", 1500);
		};

		if (GBrowserIsCompatible()) {
			'.$loadmarqueur.'
        	window.onunload=function(){window.onunload;GUnload()};
			
				if(typeof window.addEventListener != \'undefined\') {
    				window.addEventListener(\'load\', generic, false);
				} else 
					if(typeof document.addEventListener != \'undefined\') {
    					document.addEventListener(\'load\', generic, false);
					} else
						if(typeof window.attachEvent != \'undefined\') {
						    window.attachEvent(\'onload\', generic);
						} else {
						    if(typeof window.onload == \'function\') {
						        var existing = onload;
						        window.onload = function() {
						            existing();
						            generic();
        						};
    						} else {
						        window.onload = generic;
    						}
						}

		}//]]></script>');
	
	return $carte;
	}
    function getlistville()
    {
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
		
		$filtredepartement = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtredepartement', 'filtredepartement', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --', 'string' );
		$filtrepays = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrepays', 'filtrepays', '-- '.JText::_( 'NBEVENTMAP_PAYS_FILTRE' ).' --', 'string' );
		$filtrecategorie = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrecategorie', 'filtrecategorie', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --', 'string' );
		if ($filtredepartement{0}<>'-') {
			$wheres[] = 'departement = \''.addslashes($this->_getDepartementByID($filtredepartement)).'\'';
		}
		if ($filtrepays{0}<>'-') {
			$wheres[] = 'pay = \''.addslashes($this->_getPaysByID($filtrepays)).'\'';
		}	
		if ($filtrecategorie{0}<>'-') {
			$wheres[] = 'b.id = \''.$filtrecategorie.'\'';
		}

        $params = clone($mainframe->getParams('com_nbeventmap'));
		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

        $wheres[] = 'a.published = 1';
        $wheres[] = 'a.catid = b.id';

        if (!empty($this->_catid))
        {
            $_catids = $this->verif_catid($this->_catid);
            $_catids = explode( ',', $_catids );
            foreach ($_catids as $_catid)
            {
                $wheresOr[] = 'a.catid = '.$_catid.'';
            }
            $wheres[] = '('.implode( " OR ", $wheresOr).')';
        };

        $query = 'SELECT a.ville, a.id' .
                ' FROM #__nbeventmap AS a, #__categories AS b' .
                ' WHERE ' . implode( '  AND ', $wheres ).
                ' ORDER BY a.ville';
        $results = $this->_getList( $query );
		$tries=array();
		foreach ($results as $result) {
			$trie=array();
			$trie['id'] = $result->id;
			$trie['ville'] = $result->ville;
			$tries[]=$trie;
		};
        return $tries;
    }

    function getlistdepartement()
    {
		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
		
		$filtreville = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtreville', 'filtreville', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --', 'string' );
		$filtrepays = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrepays', 'filtrepays', '-- '.JText::_( 'NBEVENTMAP_PAYS_FILTRE' ).' --', 'string' );
		$filtrecategorie = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrecategorie', 'filtrecategorie', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --', 'string' );
		if ($filtreville{0}<>'-') {
			$wheres[] = 'ville = \''.addslashes($this->_getVilleByID($filtreville)).'\'';
		}
		if ($filtrepays{0}<>'-') {
			$wheres[] = 'pay = \''.addslashes($this->_getPaysByID($filtrepays)).'\'';
		}	
		if ($filtrecategorie{0}<>'-') {
			$wheres[] = 'b.id = \''.$filtrecategorie.'\'';
		}

        $params = clone($mainframe->getParams('com_nbeventmap'));
		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

        $wheres[] = 'a.published = 1';
        $wheres[] = 'a.catid = b.id';

        if (!empty($this->_catid))
        {
            $_catids = $this->verif_catid($this->_catid);
            $_catids = explode( ',', $_catids );
            foreach ($_catids as $_catid)
            {
                $wheresOr[] = 'catid = '.$_catid.'';
            }
            $wheres[] = '('.implode( " OR ", $wheresOr).')';
        };

        $query = 'SELECT a.departement, a.id' .
                ' FROM #__nbeventmap AS a, #__categories AS b' .
                ' WHERE ' . implode( '  AND ', $wheres ).
                ' ORDER BY a.departement';
        $results = $this->_getList( $query );
		$tries=array();
		foreach ($results as $result) {
			$trie=array();
			$trie['id'] = $result->id;
			$trie['departement'] = $result->departement;
			$tries[]=$trie;
		};
        return $tries;
    }

    function getlistpays()
    {
 		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
		
		$filtreville = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtreville', 'filtreville', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --', 'string' );
		$filtredepartement = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtredepartement', 'filtredepartement', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --', 'string' );
		$filtrecategorie = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrecategorie', 'filtrecategorie', '-- '.JText::_( 'NBEVENTMAP_CATEGORIE_FILTRE' ).' --', 'string' );
		if ($filtreville{0}<>'-') {
			$wheres[] = 'ville = \''.addslashes($this->_getVilleByID($filtreville)).'\'';
		}
		if ($filtredepartement{0}<>'-') {
			$wheres[] = 'departement = \''.addslashes($this->_getDepartementByID($filtredepartement)).'\'';
		}
		if ($filtrecategorie{0}<>'-') {
			$wheres[] = 'b.id = \''.$filtrecategorie.'\'';
		}

        $params = clone($mainframe->getParams('com_nbeventmap'));
		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

        $wheres[] = 'a.published = 1';
        $wheres[] = 'a.catid = b.id';

        if (!empty($this->_catid))
        {
            $_catids = $this->verif_catid($this->_catid);
            $_catids = explode( ',', $_catids );
            foreach ($_catids as $_catid)
            {
                $wheresOr[] = 'catid = '.$_catid.'';
            }
            $wheres[] = '('.implode( " OR ", $wheresOr).')';
        };

        $query = 'SELECT a.pay, a.id' .
                ' FROM #__nbeventmap AS a, #__categories AS b' .
                ' WHERE ' . implode( '  AND ', $wheres ).
                ' ORDER BY a.pay';
        $results = $this->_getList( $query );
		$tries=array();
		foreach ($results as $result) {
			$trie=array();
			$trie['id'] = $result->id;
			$trie['pay'] = $result->pay;
			$tries[]=$trie;
		};
        return $tries;
    }

    function getlistcategorie()
    {
 		$mainframe = &JFactory::getApplication(); 
		$option    = JRequest::getCMD('option'); 
		$Itemid    = JRequest::getInt('Itemid'); 
		
		$filtreville = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtreville', 'filtreville', '-- '.JText::_( 'NBEVENTMAP_VILLE_FILTRE' ).' --', 'string' );
		$filtredepartement = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtredepartement', 'filtredepartement', '-- '.JText::_( 'NBEVENTMAP_DEPARTEMENT_FILTRE' ).' --', 'string' );
		$filtrepays = $mainframe->getUserStateFromRequest( $option.$Itemid.'filtrepays', 'filtrepays', '-- '.JText::_( 'NBEVENTMAP_PAYS_FILTRE' ).' --', 'string' );
		if ($filtreville{0}<>'-') {
			$wheres[] = 'ville = \''.addslashes($this->_getVilleByID($filtreville)).'\'';
		}
		if ($filtredepartement{0}<>'-') {
			$wheres[] = 'departement = \''.addslashes($this->_getDepartementByID($filtredepartement)).'\'';
		}
		if ($filtrepays{0}<>'-') {
			$wheres[] = 'pay = \''.addslashes($this->_getPaysByID($filtrepays)).'\'';
		}	

        $params = clone($mainframe->getParams('com_nbeventmap'));
		$user_where = $params->get('nbeventmap_filtre_sql');
		if (!empty($user_where))
			$wheres[] = @$params->get('nbeventmap_filtre_sql');

        $wheres[] = 'a.published = 1';
        $wheres[] = 'a.catid = b.id';

        if (!empty($this->_catid))
        {
            $_catids = $this->verif_catid($this->_catid);
            $_catids = explode( ',', $_catids );
            foreach ($_catids as $_catid)
            {
                $wheresOr[] = 'b.id = '.$_catid.'';
            }
            $wheres[] = '('.implode( " OR ", $wheresOr).')';
        };

		$user =& JFactory::getUser();
		$aid = $user->get('aid', 0);
		

        $query = 'SELECT DISTINCT b.id, b.title' .
                ' FROM #__nbeventmap AS a, #__categories AS b' .
                ' WHERE ' . implode( '  AND ', $wheres ).
                ' ORDER BY b.title';
        return $this->_getList( $query );
    }

    function _getGoogleAPIKey()
    {
		$GoogleAPIKey = "";
		$config =& JComponentHelper::getParams('com_nbeventmap');
		if ($config->get('nbeventmap_key')) {
			$GoogleAPIKey = $config->get('nbeventmap_key');
		}else{
			$homepages = explode(";",$config->get('nbeventmap_multi_url'));
			$keys = explode(";",$config->get('nbeventmap_multi_key'));
            if ($config->get('nbeventmap_URI_type', 0)) {
                $mypage = str_replace("www.","",JURI::base());
            }else{
                $mypage = str_replace("www.","",$_SERVER["SERVER_NAME"]);
            }
			$mypage = str_replace("http://","",$mypage);
			$mypage = str_replace("http:\\","",$mypage);
			if (strpos($mypage, "/")!== false) { $mypage = substr($mypage, 0, strpos($mypage, "/")); };
			if (strpos($mypage, "\\")!== false) { $mypage = substr($mypage, 0, strpos($mypage, "\\")); };


			$i = 0;
			foreach ($homepages as $homepage){ 
				$uri = trim($homepage);
				$u =& JURI::getInstance( $uri );
				$page = str_replace("www.","",$u->getHost());
				$page = str_replace("http://","",$page);
				$page = str_replace("http:\\","",$page);
				if (strpos($page, "/")!== false) { $page = substr($page, 0, strpos($page, "/")); };
				if (strpos($page, "\\")!== false) { $page = substr($page, 0, strpos($page, "\\")); };
				
				if ($page==$mypage) {
					$GoogleAPIKey = $keys[$i];
					break;
				}
				$i++;
			}
		}
		return $GoogleAPIKey;
	}


	function _getVilleByID($id)
	{
    	$db = JFactory::getDBO();
        $query = 'SELECT a.ville' .
                ' FROM #__nbeventmap AS a' .
                ' WHERE id=' . $id;
    	$db->setQuery( $query );
		$result = $db->loadObject();
		return $result->ville;
	}


	function _getDepartementByID($id)
	{
    	$db = JFactory::getDBO();
        $query = 'SELECT a.departement' .
                ' FROM #__nbeventmap AS a' .
                ' WHERE id=' . $id;
    	$db->setQuery( $query );
		$result = $db->loadObject();
		return $result->departement;
	}


	function _getPaysByID($id)
	{
    	$db = JFactory::getDBO();
        $query = 'SELECT a.pay' .
                ' FROM #__nbeventmap AS a' .
                ' WHERE id=' . $id;
    	$db->setQuery( $query );
		$result = $db->loadObject();
		return $result->pay;
	}
	function getGnGl($id=array())
	{
    	$db = JFactory::getDBO();
        $query = 'SELECT a.glat,a.glng' .
                ' FROM #__nbeventmap AS a' .
                ' WHERE (SUBSTRING(a.start_date,1,4)) IN ' . $id;
    	$db->setQuery( $query );
		$result = $db->loadObjectList();
		return $result;
	}
	
	function getGallery($id) {
		$db = JFactory::getDBO();
		$query = 'SELECT f.* '.
				'FROM #__nbeventmap_files as f '.
				'INNER JOIN #__nbeventmap as a ON f.event_id = a.id '.
				'WHERE 	a.id ='.(int)$id.' AND a.published =1';
		$db->setQuery( $query );
		$result = $db->loadObjectList();
		return $result;
	}
}
?>
